package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.example.wyy.R;

import java.util.List;
import java.util.Map;

import entiy.Rec;

public class GridViewAdapter extends BaseAdapter
{
    private Context context;
    private List<Rec> recs;

    public GridViewAdapter(Context context, List<Rec> recs) {
        this.context = context;
        this.recs = recs;
    }

    public GridViewAdapter() {
    }

    @Override
    public int getCount() {
        return recs.size();
    }

    @Override
    public Rec getItem(int position) {
        return recs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = new Holder();
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_recommend,parent,false);
            holder.imageView = convertView.findViewById(R.id.recommendation_img);
            holder.textView = convertView.findViewById(R.id.recommendation);
            convertView.setTag(holder);
        }else {
             holder =  (Holder) convertView.getTag();
        }
        holder.imageView.setImageResource(getItem(position).getImg());
        holder.textView.setText(getItem(position).getDesc());
        return convertView;
    }
    class Holder {
        public TextView textView;
        public ImageView imageView;
    }
}
